package com.A21.GuoSai.demo.service_entity.test;

import com.A21.GuoSai.demo.service_entity.entity.atom.StaticVarPojo;
import com.A21.GuoSai.demo.service_entity.entity.workflow.EndEventPojo;
import com.A21.GuoSai.demo.service_entity.entity.workflow.ExpressionFlowPojo;
import com.A21.GuoSai.demo.service_entity.utils.BpmnUtils;
import io.camunda.zeebe.model.bpmn.BpmnModelInstance;
import org.camunda.feel.FeelEngine;
import org.junit.jupiter.api.Test;
import scala.util.Either;
import scala.util.Left;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TryAnalizeBpmn {
    @Test
    public void analizeBpmn() throws IOException {
        InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream("processes/purchase.bpmn");
        BufferedReader reader=new BufferedReader(new InputStreamReader(resourceAsStream));
        String bpmn="";
        String readmess;
        while ((readmess=reader.readLine()) != null) {
            bpmn += readmess;
        }

        BpmnModelInstance modelInstance = BpmnUtils.getModelInstance(bpmn);
        List<ExpressionFlowPojo> allExpressionFlows=BpmnUtils.getAllExpressionFlows(modelInstance);
//        list.forEach(expressionFlowPojo -> System.out.println(expressionFlowPojo.toString()));

        FeelEngine feelEngine=new FeelEngine.Builder().build();
        Map<String,Object> map=new HashMap<>();
        Either<FeelEngine.Failure, Object> failureObjectEither = feelEngine.evalExpression("commodity.data = 30", map);

        System.out.println(((Left)failureObjectEither).value());
        List<EndEventPojo> allEndEvents = BpmnUtils.getAllEndEvents(modelInstance);
    }


    @Test
    public void JudgeTest01(){
        //创建一个新的Feel语言引擎
        FeelEngine feelEngine=new FeelEngine.Builder().build();
        Map<String,Object> map=new HashMap<>();

        //
        Either<FeelEngine.Failure, Object> failureObjectEither = feelEngine.evalExpression("commodity.data > 30", map);
        System.out.println(failureObjectEither.toString());
    }

    @Test
    public void tryToCast() throws Exception {
        StaticVarPojo varPojo=new StaticVarPojo();
        varPojo.setAtomId(1);
//        varPojo.setFlowId(2);
        varPojo.setS_name("ddd");
//        varPojo.setType(Integer.class);
//        varPojo.setType("java.lang.String");
//        varPojo.setValue("1.592");

//        System.out.println(varPojo.getValue());
        System.out.println(varPojo.toString());
    }
}
